# PDF加密UI
from info import user_info_jiam
from PyQt5.QtCore import QRect, QCoreApplication
from PyQt5.QtWidgets import QLabel, QLineEdit, QPushButton, QMessageBox, QMainWindow, QFileDialog


class PDF_Encrypt_UI(QMainWindow):
    def setupUi(self):
        self.resize(550, 100)
        self.label = QLabel(self)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(9, 19, 132, 16))
        self.lineEdit = QLineEdit(self)
        self.lineEdit.setObjectName(u"lineEdit")
        self.lineEdit.setGeometry(QRect(147, 19, 201, 20))
        self.pushButton = QPushButton(self)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.setGeometry(QRect(450, 20, 91, 51))
        self.pushButton.clicked.connect(self.pubshbutton_click)
        self.label_2 = QLabel(self)
        self.label_2.setObjectName(u"label_2")
        self.label_2.setGeometry(QRect(9, 55, 60, 16))
        self.lineEdit_2 = QLineEdit(self)
        self.lineEdit_2.setObjectName(u"lineEdit_2")
        self.lineEdit_2.setGeometry(QRect(147, 55, 201, 20))
        self.retranslateUi()
        self.Button2()

    def retranslateUi(self):
        self.setWindowTitle(QCoreApplication.translate("Form", user_info_jiam, None))
        self.label.setText(
            QCoreApplication.translate("Form", u"\u8bf7\u9009\u62e9\u9700\u8981\u52a0\u5bc6\u7684\u6587\u4ef6\uff1a",
                                       None))
        self.pushButton.setText(QCoreApplication.translate("Form", u"\u52a0\u5bc6", None))
        self.label_2.setText(QCoreApplication.translate("Form", u"\u8bbe\u7f6e\u5bc6\u7801\uff1a", None))

    def Button2(self):
        button = QPushButton(self)
        button.setText("浏览文件")
        button.setGeometry(QRect(350, 20, 91, 51))
        button.clicked.connect(self.Button2_click)

    def Button2_click(self):
        file = QFileDialog.getOpenFileName(self, "打开文件", "./", "PDF(*.pdf)")
        if file:
            self.lineEdit.setText(str(file[0]))

    def pubshbutton_click(self):
        filename = self.lineEdit.text()
        password = self.lineEdit_2.text()
        if filename == "" or password == "":
            self.msg_box = QMessageBox(QMessageBox.Warning, "警告", "未输入密码或未选择文件")
        else:
            # 引用加密程序
            from pdf_jm import pdf_encrypt
            pdf_jm = pdf_encrypt(filename, password)
            if pdf_jm == 1:
                self.msg_box = QMessageBox(QMessageBox.Information, "提示", "文件加密成功，应在源文件目录下寻找", QMessageBox.Ok)
            else:
                self.msg_box = QMessageBox(QMessageBox.Warning, "警告", "文件加密失败，请稍后重试！", QMessageBox.Ok)

        return self.msg_box.show()
